package com.frcdi.qms.web.controller.masterdata;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.masterdata.domain.MethodExecute;
import com.frcdi.qms.masterdata.service.IMethodExecuteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 方法执行步骤记录Controller
 *
 * @author cell
 * @date 2023-12-19
 */
@Api(tags = "方法执行步骤记录")
@RestController
@RequestMapping("/equipment/execute")
public class MethodExecuteController extends BaseController
{
    @Autowired
    private IMethodExecuteService methodExecuteService;

    /**
     * 查询方法执行步骤记录列表
     */
    @ApiOperation("查询方法执行步骤记录列表")
//    @PreAuthorize("@ss.hasPermi('equipment:execute:list')")
    @GetMapping("/list")
    public TableDataInfo list(MethodExecute methodExecute)
    {
        startPage();
        List<MethodExecute> list = methodExecuteService.selectMethodExecuteList(methodExecute);
        return getDataTable(list);
    }

    /**
     * 导出方法执行步骤记录列表
     */
    @ApiOperation("导出方法执行步骤记录列表")
//    @PreAuthorize("@ss.hasPermi('equipment:execute:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MethodExecute methodExecute)
    {
        List<MethodExecute> list = methodExecuteService.selectMethodExecuteList(methodExecute);
        ExcelUtil<MethodExecute> util = new ExcelUtil<MethodExecute>(MethodExecute.class);
        util.exportExcel(response, list, "方法执行步骤记录数据");
    }

    /**
     * 获取方法执行步骤记录详细信息
     */
    @ApiOperation("获取方法执行步骤记录详细信息")
//    @PreAuthorize("@ss.hasPermi('equipment:execute:query')")
    @GetMapping(value = "/{executeId}")
    public AjaxResult getInfo(@PathVariable("executeId") Long executeId)
    {
        return success(methodExecuteService.selectMethodExecuteByExecuteId(executeId));
    }

    /**
     * 新增方法执行步骤记录
     */
    @ApiOperation("新增方法执行步骤记录")
//    @PreAuthorize("@ss.hasPermi('equipment:execute:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MethodExecute methodExecute)
    {
        methodExecute.setCreateBy(getUsername());
        return toAjax(methodExecuteService.insertMethodExecute(methodExecute));
    }

    /**
     * 删除方法执行步骤记录
     */
    @ApiOperation("删除方法执行步骤记录")
//    @PreAuthorize("@ss.hasPermi('equipment:execute:remove')")
    @DeleteMapping("/{executeIds}")
    public AjaxResult remove(@PathVariable Long[] executeIds)
    {
        return toAjax(methodExecuteService.deleteMethodExecuteByExecuteIds(executeIds));
    }
}
